#include "ModelInfoQuery.h"
#include "Assembly.h"
#include "SGFem/Pre/Assembly/CoordinateProcessor.h"

using namespace SG::DataStructure::FEM;
using SG::FEMSolver::ModelInfoQuery;
using SG::FEMSolver::AssemblyEigen;

void ModelInfoQuery::QueryNode (const std::shared_ptr<SG::DBManager::INodeService>& nodeRepository, const SG::DataStructure::Common::Id* const nodeIdSet, const int nNode, SG::Algebra::PointArray& _OUT points, std::vector<std::size_t>& _OUT nodeIndexes, std::vector<SG::DataStructure::Common::Id>& _OUT dispCoordIds)
{
    // get global infomation
    auto&       assembly       = SG::FEMSolver::AssemblyEigen::GetInstance ();
    const auto& coordProcessor = CoordinateProcessor::GetInstance ();

    // reset vector size
    points.resize(nNode);
    nodeIndexes.resize(nNode);
    dispCoordIds.resize(nNode);

    assembly.FindNodeIndex (nodeIdSet, _OUT nodeIndexes);
    NodeData   node;
    for (auto index = 0; index != nNode; ++index)
    {
        // query node from db
        nodeRepository->FindByIndex (nodeIndexes[index], _OUT node);
        coordProcessor.GetGlobalCoordinate (node, _OUT points[index], _OUT dispCoordIds[index]);
    }
}